
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/18/2011 16:17:35
-- Generated from EDMX file: D:\Vishal\Vishal-Projects\Dropbox\TicketApp\TicketApp\TicketsModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [TicketAppDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_EventOrganizer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Events] DROP CONSTRAINT [FK_EventOrganizer];
GO
IF OBJECT_ID(N'[dbo].[FK_EventAgent_Event]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventAgent] DROP CONSTRAINT [FK_EventAgent_Event];
GO
IF OBJECT_ID(N'[dbo].[FK_EventAgent_Agent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventAgent] DROP CONSTRAINT [FK_EventAgent_Agent];
GO
IF OBJECT_ID(N'[dbo].[FK_UserAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AllUsers] DROP CONSTRAINT [FK_UserAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AllUsers] DROP CONSTRAINT [FK_UserRole];
GO
IF OBJECT_ID(N'[dbo].[FK_VenueAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Venues] DROP CONSTRAINT [FK_VenueAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTypeTicketQuota]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketQuotas] DROP CONSTRAINT [FK_TicketTypeTicketQuota];
GO
IF OBJECT_ID(N'[dbo].[FK_AgentBranchAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AgentBranches] DROP CONSTRAINT [FK_AgentBranchAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_AgentBranchAgent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AgentBranches] DROP CONSTRAINT [FK_AgentBranchAgent];
GO
IF OBJECT_ID(N'[dbo].[FK_AgentBranchTicketQuota]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketQuotas] DROP CONSTRAINT [FK_AgentBranchTicketQuota];
GO
IF OBJECT_ID(N'[dbo].[FK_CustomerTicket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tickets] DROP CONSTRAINT [FK_CustomerTicket];
GO
IF OBJECT_ID(N'[dbo].[FK_PaymentTicket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tickets] DROP CONSTRAINT [FK_PaymentTicket];
GO
IF OBJECT_ID(N'[dbo].[FK_PaymentCustomer_Payment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PaymentCustomer] DROP CONSTRAINT [FK_PaymentCustomer_Payment];
GO
IF OBJECT_ID(N'[dbo].[FK_PaymentCustomer_Customer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PaymentCustomer] DROP CONSTRAINT [FK_PaymentCustomer_Customer];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTicketQuota]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tickets] DROP CONSTRAINT [FK_TicketTicketQuota];
GO
IF OBJECT_ID(N'[dbo].[FK_EventTicketType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketTypes] DROP CONSTRAINT [FK_EventTicketType];
GO
IF OBJECT_ID(N'[dbo].[FK_VenueTicketType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketTypes] DROP CONSTRAINT [FK_VenueTicketType];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTypeContact]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contacts] DROP CONSTRAINT [FK_TicketTypeContact];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTemplateTicketType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketTypes] DROP CONSTRAINT [FK_TicketTemplateTicketType];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Events]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Events];
GO
IF OBJECT_ID(N'[dbo].[Addresses]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Addresses];
GO
IF OBJECT_ID(N'[dbo].[Contacts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contacts];
GO
IF OBJECT_ID(N'[dbo].[TicketTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketTypes];
GO
IF OBJECT_ID(N'[dbo].[AllUsers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AllUsers];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Roles];
GO
IF OBJECT_ID(N'[dbo].[TicketQuotas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketQuotas];
GO
IF OBJECT_ID(N'[dbo].[Venues]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Venues];
GO
IF OBJECT_ID(N'[dbo].[AgentBranches]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AgentBranches];
GO
IF OBJECT_ID(N'[dbo].[Tickets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tickets];
GO
IF OBJECT_ID(N'[dbo].[Payments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Payments];
GO
IF OBJECT_ID(N'[dbo].[TicketTemplates]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketTemplates];
GO
IF OBJECT_ID(N'[dbo].[EventAgent]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EventAgent];
GO
IF OBJECT_ID(N'[dbo].[PaymentCustomer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PaymentCustomer];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Events'
CREATE TABLE [dbo].[Events] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [StartDateTime] datetime  NOT NULL,
    [EndDateTime] datetime  NOT NULL,
    [Timezone] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Status] int  NOT NULL,
    [Organizers_Id] int  NOT NULL
);
GO

-- Creating table 'Addresses'
CREATE TABLE [dbo].[Addresses] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Line1] nvarchar(max)  NOT NULL,
    [Line2] nvarchar(max)  NOT NULL,
    [City] nvarchar(max)  NOT NULL,
    [State] nvarchar(max)  NOT NULL,
    [Country] nvarchar(max)  NOT NULL,
    [PostalCode] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Contacts'
CREATE TABLE [dbo].[Contacts] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [TicketType_Id] int  NOT NULL
);
GO

-- Creating table 'TicketTypes'
CREATE TABLE [dbo].[TicketTypes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [Price] decimal(18,0)  NOT NULL,
    [TotalQuantity] int  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [EventDate] datetime  NOT NULL,
    [Status] nvarchar(max)  NOT NULL,
    [CustomTemplate] nvarchar(max)  NOT NULL,
    [Event_Id] int  NOT NULL,
    [Venue_Id] int  NOT NULL,
    [TicketTemplate_Id] int  NOT NULL
);
GO

-- Creating table 'AllUsers'
CREATE TABLE [dbo].[AllUsers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [Status] int  NOT NULL,
    [__Disc__] nvarchar(4000)  NOT NULL,
    [Address_Id] int  NOT NULL,
    [Role_Id] int  NOT NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TicketQuotas'
CREATE TABLE [dbo].[TicketQuotas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [QuotaQuantity] int  NOT NULL,
    [TicketType_Id] int  NOT NULL,
    [AgentBranch_Id] int  NOT NULL
);
GO

-- Creating table 'Venues'
CREATE TABLE [dbo].[Venues] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Address_Id] int  NOT NULL
);
GO

-- Creating table 'AgentBranches'
CREATE TABLE [dbo].[AgentBranches] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Address_Id] int  NOT NULL,
    [Agent_Id] int  NOT NULL
);
GO

-- Creating table 'Tickets'
CREATE TABLE [dbo].[Tickets] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [PhysicalTicketNumber] nvarchar(max)  NOT NULL,
    [EventDate] datetime  NOT NULL,
    [ElectornicTicketNumber] uniqueidentifier  NOT NULL,
    [Barcode] nvarchar(max)  NOT NULL,
    [Customer_Id] int  NOT NULL,
    [Payment_Id] int  NOT NULL,
    [TicketQuota_Id] int  NOT NULL
);
GO

-- Creating table 'Payments'
CREATE TABLE [dbo].[Payments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Mode] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TicketTemplates'
CREATE TABLE [dbo].[TicketTemplates] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Template] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'EventAgent'
CREATE TABLE [dbo].[EventAgent] (
    [Events_Id] int  NOT NULL,
    [Agents_Id] int  NOT NULL
);
GO

-- Creating table 'PaymentCustomer'
CREATE TABLE [dbo].[PaymentCustomer] (
    [Payments_Id] int  NOT NULL,
    [Customers_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Events'
ALTER TABLE [dbo].[Events]
ADD CONSTRAINT [PK_Events]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Addresses'
ALTER TABLE [dbo].[Addresses]
ADD CONSTRAINT [PK_Addresses]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [PK_Contacts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TicketTypes'
ALTER TABLE [dbo].[TicketTypes]
ADD CONSTRAINT [PK_TicketTypes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AllUsers'
ALTER TABLE [dbo].[AllUsers]
ADD CONSTRAINT [PK_AllUsers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TicketQuotas'
ALTER TABLE [dbo].[TicketQuotas]
ADD CONSTRAINT [PK_TicketQuotas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Venues'
ALTER TABLE [dbo].[Venues]
ADD CONSTRAINT [PK_Venues]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AgentBranches'
ALTER TABLE [dbo].[AgentBranches]
ADD CONSTRAINT [PK_AgentBranches]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Tickets'
ALTER TABLE [dbo].[Tickets]
ADD CONSTRAINT [PK_Tickets]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Payments'
ALTER TABLE [dbo].[Payments]
ADD CONSTRAINT [PK_Payments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TicketTemplates'
ALTER TABLE [dbo].[TicketTemplates]
ADD CONSTRAINT [PK_TicketTemplates]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Events_Id], [Agents_Id] in table 'EventAgent'
ALTER TABLE [dbo].[EventAgent]
ADD CONSTRAINT [PK_EventAgent]
    PRIMARY KEY NONCLUSTERED ([Events_Id], [Agents_Id] ASC);
GO

-- Creating primary key on [Payments_Id], [Customers_Id] in table 'PaymentCustomer'
ALTER TABLE [dbo].[PaymentCustomer]
ADD CONSTRAINT [PK_PaymentCustomer]
    PRIMARY KEY NONCLUSTERED ([Payments_Id], [Customers_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Organizers_Id] in table 'Events'
ALTER TABLE [dbo].[Events]
ADD CONSTRAINT [FK_EventOrganizer]
    FOREIGN KEY ([Organizers_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventOrganizer'
CREATE INDEX [IX_FK_EventOrganizer]
ON [dbo].[Events]
    ([Organizers_Id]);
GO

-- Creating foreign key on [Events_Id] in table 'EventAgent'
ALTER TABLE [dbo].[EventAgent]
ADD CONSTRAINT [FK_EventAgent_Event]
    FOREIGN KEY ([Events_Id])
    REFERENCES [dbo].[Events]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Agents_Id] in table 'EventAgent'
ALTER TABLE [dbo].[EventAgent]
ADD CONSTRAINT [FK_EventAgent_Agent]
    FOREIGN KEY ([Agents_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventAgent_Agent'
CREATE INDEX [IX_FK_EventAgent_Agent]
ON [dbo].[EventAgent]
    ([Agents_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'AllUsers'
ALTER TABLE [dbo].[AllUsers]
ADD CONSTRAINT [FK_UserAddress]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[Addresses]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserAddress'
CREATE INDEX [IX_FK_UserAddress]
ON [dbo].[AllUsers]
    ([Address_Id]);
GO

-- Creating foreign key on [Role_Id] in table 'AllUsers'
ALTER TABLE [dbo].[AllUsers]
ADD CONSTRAINT [FK_UserRole]
    FOREIGN KEY ([Role_Id])
    REFERENCES [dbo].[Roles]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserRole'
CREATE INDEX [IX_FK_UserRole]
ON [dbo].[AllUsers]
    ([Role_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'Venues'
ALTER TABLE [dbo].[Venues]
ADD CONSTRAINT [FK_VenueAddress]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[Addresses]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VenueAddress'
CREATE INDEX [IX_FK_VenueAddress]
ON [dbo].[Venues]
    ([Address_Id]);
GO

-- Creating foreign key on [TicketType_Id] in table 'TicketQuotas'
ALTER TABLE [dbo].[TicketQuotas]
ADD CONSTRAINT [FK_TicketTypeTicketQuota]
    FOREIGN KEY ([TicketType_Id])
    REFERENCES [dbo].[TicketTypes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTypeTicketQuota'
CREATE INDEX [IX_FK_TicketTypeTicketQuota]
ON [dbo].[TicketQuotas]
    ([TicketType_Id]);
GO

-- Creating foreign key on [Address_Id] in table 'AgentBranches'
ALTER TABLE [dbo].[AgentBranches]
ADD CONSTRAINT [FK_AgentBranchAddress]
    FOREIGN KEY ([Address_Id])
    REFERENCES [dbo].[Addresses]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgentBranchAddress'
CREATE INDEX [IX_FK_AgentBranchAddress]
ON [dbo].[AgentBranches]
    ([Address_Id]);
GO

-- Creating foreign key on [Agent_Id] in table 'AgentBranches'
ALTER TABLE [dbo].[AgentBranches]
ADD CONSTRAINT [FK_AgentBranchAgent]
    FOREIGN KEY ([Agent_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgentBranchAgent'
CREATE INDEX [IX_FK_AgentBranchAgent]
ON [dbo].[AgentBranches]
    ([Agent_Id]);
GO

-- Creating foreign key on [AgentBranch_Id] in table 'TicketQuotas'
ALTER TABLE [dbo].[TicketQuotas]
ADD CONSTRAINT [FK_AgentBranchTicketQuota]
    FOREIGN KEY ([AgentBranch_Id])
    REFERENCES [dbo].[AgentBranches]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgentBranchTicketQuota'
CREATE INDEX [IX_FK_AgentBranchTicketQuota]
ON [dbo].[TicketQuotas]
    ([AgentBranch_Id]);
GO

-- Creating foreign key on [Customer_Id] in table 'Tickets'
ALTER TABLE [dbo].[Tickets]
ADD CONSTRAINT [FK_CustomerTicket]
    FOREIGN KEY ([Customer_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomerTicket'
CREATE INDEX [IX_FK_CustomerTicket]
ON [dbo].[Tickets]
    ([Customer_Id]);
GO

-- Creating foreign key on [Payment_Id] in table 'Tickets'
ALTER TABLE [dbo].[Tickets]
ADD CONSTRAINT [FK_PaymentTicket]
    FOREIGN KEY ([Payment_Id])
    REFERENCES [dbo].[Payments]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PaymentTicket'
CREATE INDEX [IX_FK_PaymentTicket]
ON [dbo].[Tickets]
    ([Payment_Id]);
GO

-- Creating foreign key on [Payments_Id] in table 'PaymentCustomer'
ALTER TABLE [dbo].[PaymentCustomer]
ADD CONSTRAINT [FK_PaymentCustomer_Payment]
    FOREIGN KEY ([Payments_Id])
    REFERENCES [dbo].[Payments]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Customers_Id] in table 'PaymentCustomer'
ALTER TABLE [dbo].[PaymentCustomer]
ADD CONSTRAINT [FK_PaymentCustomer_Customer]
    FOREIGN KEY ([Customers_Id])
    REFERENCES [dbo].[AllUsers]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PaymentCustomer_Customer'
CREATE INDEX [IX_FK_PaymentCustomer_Customer]
ON [dbo].[PaymentCustomer]
    ([Customers_Id]);
GO

-- Creating foreign key on [TicketQuota_Id] in table 'Tickets'
ALTER TABLE [dbo].[Tickets]
ADD CONSTRAINT [FK_TicketTicketQuota]
    FOREIGN KEY ([TicketQuota_Id])
    REFERENCES [dbo].[TicketQuotas]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTicketQuota'
CREATE INDEX [IX_FK_TicketTicketQuota]
ON [dbo].[Tickets]
    ([TicketQuota_Id]);
GO

-- Creating foreign key on [Event_Id] in table 'TicketTypes'
ALTER TABLE [dbo].[TicketTypes]
ADD CONSTRAINT [FK_EventTicketType]
    FOREIGN KEY ([Event_Id])
    REFERENCES [dbo].[Events]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventTicketType'
CREATE INDEX [IX_FK_EventTicketType]
ON [dbo].[TicketTypes]
    ([Event_Id]);
GO

-- Creating foreign key on [Venue_Id] in table 'TicketTypes'
ALTER TABLE [dbo].[TicketTypes]
ADD CONSTRAINT [FK_VenueTicketType]
    FOREIGN KEY ([Venue_Id])
    REFERENCES [dbo].[Venues]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VenueTicketType'
CREATE INDEX [IX_FK_VenueTicketType]
ON [dbo].[TicketTypes]
    ([Venue_Id]);
GO

-- Creating foreign key on [TicketType_Id] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [FK_TicketTypeContact]
    FOREIGN KEY ([TicketType_Id])
    REFERENCES [dbo].[TicketTypes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTypeContact'
CREATE INDEX [IX_FK_TicketTypeContact]
ON [dbo].[Contacts]
    ([TicketType_Id]);
GO

-- Creating foreign key on [TicketTemplate_Id] in table 'TicketTypes'
ALTER TABLE [dbo].[TicketTypes]
ADD CONSTRAINT [FK_TicketTemplateTicketType]
    FOREIGN KEY ([TicketTemplate_Id])
    REFERENCES [dbo].[TicketTemplates]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTemplateTicketType'
CREATE INDEX [IX_FK_TicketTemplateTicketType]
ON [dbo].[TicketTypes]
    ([TicketTemplate_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------